import 'package:get/get.dart';
import 'package:znmm/UI/utils/my_global.dart';
import 'package:znmm/config/app_init.dart';
import 'package:znmm/config/app_routes.dart';

class UserInfoMag {
  static final UserInfoMag _singleton = UserInfoMag._internal();
  factory UserInfoMag() {
    return _singleton;
  }

  UserInfoMag._internal();

  //登录后保存用户名和密码
  String username = "";
  String password = "";
  //登录的info
  String user_id = "";
  String display_name = "";
  String email = "";

  //是否是游客 默认游客
  bool _bIsVisitor = true;
  bool get bIsVisito => _bIsVisitor;

  void clearn() {
    username = "";
    password = "";
    user_id = "";
    display_name = "";
    email = "";
    _bIsVisitor = true;
  }

  //用户基本信息
  void fromJson(
    Map<String, dynamic> json,
    String usName,
    String pwd,
  ) {
    username = usName;
    password = pwd;

    user_id = MyGlobal.checkNullOrEmpty(json["user_id"]);
    display_name = MyGlobal.checkNullOrEmpty(json["display_name"]);
    email = MyGlobal.checkNullOrEmpty(json["email"]);

    _bIsVisitor = false;

    AppInit.loginSuccessInit();
  }

  void doSomething() {
    print("Doing something...");
  }

  //跳转到第几页
  void jumpToBottomPage(int iPageIndex) async {
    Get.offAllNamed(RouteNames.homeRoute, arguments: {'iPageTag': iPageIndex});
  }
}


/*

{
  user_id: 23,
  first_name: ,
  last_name: ,
  display_name: 157,
  role: Customer,
  avatar_urls: {
    24: https: //secure.gravatar.com/avatar/9b5a2aaa061addded71dce1e34430754?s=24&d=mm&r=g,
    48: https: //secure.gravatar.com/avatar/9b5a2aaa061addded71dce1e34430754?s=48&d=mm&r=g,
    96: https: //secure.gravatar.com/avatar/9b5a2aaa061addded71dce1e34430754?s=96&d=mm&r=g
  },
  email: 157@qq.com,
  extras: [
    
  ],
  dev_note: Don't forget to store the users login information in order to authenticate all other routes with CoCart.}

*/